#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
struct word
{
    string letter, mean;
};
void check(word x)
{
    for(int i = 1; i <= 3; i++)
    {
        HANDLE handle;
        handle=GetStdHandle(STD_OUTPUT_HANDLE);
        SetConsoleTextAttribute(handle,0xF);
        cout << x.mean << ": ";
        string t;
        cin >> t;
        if(t == x.letter)
        {
            HANDLE handle;
            handle=GetStdHandle(STD_OUTPUT_HANDLE);
            SetConsoleTextAttribute(handle,0xA);
            cout << "正确！\n";
            MessageBeep(1);
            return;
        }
        HANDLE handle2;
        handle2=GetStdHandle(STD_OUTPUT_HANDLE);
        SetConsoleTextAttribute(handle2,0xC);
        cout << "错误！\n";
        MessageBeep(MB_ICONERROR);
    }
}
int main()
{
    fstream fin("wordlist.ls", ios::in | ios::app);
	time_t t = time(0);
	tm* ti = localtime(&t);
	cout << "日期：" << ti->tm_year + 1900 << "年" << ti->tm_mon << "月" << ti->tm_mday << "日\n";
    while(true)
    {
        system("cls");
        HANDLE handle;
        handle=GetStdHandle(STD_OUTPUT_HANDLE);
        SetConsoleTextAttribute(handle,0xF);
    	cout << "欢迎使用智能单词背诵系统！\n1.复习\n2.学习\n3.退出\n输入你的选择：";
        int n;
        cin >> n;
        if(n == 1)
        {
            system("cls");
            HANDLE handle;
            handle=GetStdHandle(STD_OUTPUT_HANDLE);
            SetConsoleTextAttribute(handle,0xF);
            vector<word> words;
            string wor;
            string tran;
            int a;
            while(fin >> wor >> tran >> a)
            {
                if((t - a + 80000) / 86400 <= 7)
                {
                    words.push_back({wor, tran});
                }
            }
            for(auto i : words)
            {
                check(i);
            }
            HANDLE handle2;
            handle2=GetStdHandle(STD_OUTPUT_HANDLE);
            SetConsoleTextAttribute(handle2,0xF);
            system("pause");
        }
        else if(n == 2)
        {
            system("cls");
            cout << "请不要输入空格！按下 <ctrl> + z + <enter> 结束输入\n";
            cout << "输入示例：\napple（原词） 苹果（译文）\n -----------\n请开始输入：\n";
            string w, m;
            while(cin >> w >> m)
            {
                fin << w << ' ' << m << ' ' << t << '\n';
            }
            HANDLE handle;
            handle=GetStdHandle(STD_OUTPUT_HANDLE);
            SetConsoleTextAttribute(handle,0xF);
            system("pause");
        }
        else if(n == 3)
        {
            break;
        }
        else
        {
            cout << "输入有误！\n";
            system("pahse");
        }
    }
	return 0;
}